﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Medical_Store_Billing.Component;

namespace Medical_Store_Billing
{
    public partial class Restore : Form
    {
        public Restore()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog oDialog = new OpenFileDialog();
            if (oDialog.ShowDialog() == DialogResult.OK)
            {
                txtfile.Text = oDialog.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {

            String sql = "ALTER DATABASE medicalstorebilling SET SINGLE_USER WITH ROLLBACK IMMEDIATE ; use master RESTORE DATABASE medicalstorebilling FROM DISK  ='" + txtfile.Text + "' with nounload,replace";
            SqlConnection conn = new SqlConnection(Dataservice.m_ConnectString);
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            cmd.ExecuteNonQuery();
            MessageBox.Show("Restore thang cong");
            conn.Close();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}
